package com.atguigu.controller;

import com.atguigu.entity.BaseBrand;
import com.atguigu.entity.BaseCategoryView;
import com.atguigu.entity.ProductSalePropertyKey;
import com.atguigu.entity.SkuInfo;
import com.atguigu.service.BaseBrandService;
import com.atguigu.service.BaseCategoryViewService;
import com.atguigu.service.SkuDetailService;
import com.atguigu.service.SkuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sku/")
public class SkuDetailController {
    @Autowired
    private SkuDetailService skuDetailService;
    @Autowired
    private SkuInfoService skuInfoService;
    @Autowired
    private BaseCategoryViewService categoryViewService;
    @Autowired
    private BaseBrandService brandService;

    //1.根据skuid获取sku的基本信息(skuInfo)
    @GetMapping("getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable Long skuId){
        return skuDetailService.getSkuInfo(skuId);
    }
    //2.根据skuid获取spu的销售属性
    @GetMapping("getSpuSaleProperty/{productId}/{skuId}")
    public List<ProductSalePropertyKey> getSpuSaleProperty(@PathVariable Long productId, @PathVariable Long skuId){
        return skuDetailService.getSpuSaleProperty(productId,skuId);
    }
    //3.根据skuid获取sku的实时价格信息
    @GetMapping("getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable Long skuId){
        SkuInfo skuInfo = skuInfoService.getById(skuId);
        return skuInfo.getPrice();
    }
    //4.根据skuid获取sku的分类信息
    @GetMapping("getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(@PathVariable Long category3Id){
        return categoryViewService.getById(category3Id);
    }
    //5.根据spuId获取该spu所对应的所有sku的销售属性值与sku的对应关系
    @GetMapping("getSkuSalePropertyValueIdMapping/{productId}")
    public Map getSkuSalePropertyValueIdMapping(@PathVariable Long productId){
        return skuDetailService.getSkuSalePropertyValueIdMapping(productId);
    }
    //6.通过brandId查询品牌信息
    @GetMapping("getBrandById/{brandId}")
    public BaseBrand getBrandById(@PathVariable Long brandId){
        return brandService.getById(brandId);
    }

}
